def is_prime(n):
  
  if n % 2 == 0:
    return n == 2
  for i in range(3, int(n ** 0.5) + 1, 2):
    if n % i == 0:
      return False 
  return True

def print_answer(n):
  if is_prime(n):
    print(n)
    return False 
  return True

words = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
input = input().split()

if len(input) != 3 or \
    (input[0] not in words) or (input[1] not in words) or (input[2] not in words) or \
   input[0] == "zero":
  print("Wrong input")
else:
  n = words.index(input[0]) * 100 + words.index(input[1]) * 10 + words.index(input[2])
  

  
  
  i = 0
  while print_answer(n - i) and print_answer(n + i):
    i += 1
